package com.jk.controller;

import com.jk.pojo.PostBean;
import com.jk.pojo.UserBean;
import com.jk.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 2 * @author lujintao
 * 3 * @description 类描述
 * 4 * @date 2021/11/16
 * 5 * @version </pre>
 * 6
 */
@Controller
@RequestMapping("log")
public class LogController {
    @Autowired
    private LogService logService;

    @RequestMapping("text")
    @ResponseBody
    public String text(){
        return "我就****";
    }
    @GetMapping("loginUser")
    @ResponseBody
    public Map<String,String> loginUser(UserBean q){
        System.out.println("调用成功");
        System.out.println(q);
        Map<String,String> map = new HashMap<>();
        UserBean w=logService.findUserId(q.getName());
        if (w==null){
            map.put("message","用户名不存在");
            return map;
        }
        if (!q.getPassword().equals(w.getPassword())){
            map.put("message","密码错误");
            return map;
        }
        map.put("message","登录成功！！！");
        return map;
    }
    @GetMapping("SessUser")
    @ResponseBody
    public UserBean SessUser(String name){
        return logService.findUserId(name);
    }
    @PostMapping("addUser")
    @ResponseBody
    public void addUser(@RequestBody UserBean w){
        logService.addUser(w);
    }
    @GetMapping("selectAdmin")
    @ResponseBody
    public List<UserBean> selectAdmin(){
        return logService.selectAdmin();
    }
    @GetMapping("selectPort")
    @ResponseBody
    public List<PostBean> selectPort(){
        return logService.selectPort();
    }
    @PostMapping("addPost")
    @ResponseBody
    public void addPost(@RequestBody PostBean e){
        logService.addPost(e);
    }

}
